package com.zkca.xf.utils;

import android.content.Context;
import android.widget.Toast;

/**
 * Created by Twilight on 2015/1/20.
 */
public class ToastUtils {
    public static Toast toast;

    private ToastUtils() {
        throw new AssertionError();
    }

    public static void show(Context context, int resId) {
        if(context==null)return;
        if(toast != null)
            toast.cancel();
        toast = Toast.makeText(context, context.getResources().getText(resId), Toast.LENGTH_SHORT);
        toast.show();
    }

    public static void show(Context context, int resId, int duration) {
        if(context==null)return;
        if(toast != null)
            toast.cancel();
        toast = Toast.makeText(context, context.getResources().getText(resId), duration);
        toast.show();
    }

    public static void show(Context context, CharSequence text) {
        if(context==null)return;
        if(toast != null)
            toast.cancel();
        toast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
        toast.show();
    }

    public static void show(Context context, CharSequence text, int duration) {
        if(context==null)return;
        if(toast != null)
            toast.cancel();
        toast = Toast.makeText(context, text, duration);
        toast.show();
    }

    public static void show(Context context, int resId, Object... args) {
        if(context==null)return;
        if(toast != null)
            toast.cancel();
        toast = Toast.makeText(context, String.format(context.getResources().getString(resId), args), Toast.LENGTH_SHORT);
        toast.show();
    }

    public static void show(Context context, String format, Object... args) {
        if(context==null)return;
        if(toast != null)
            toast.cancel();
        toast = Toast.makeText(context, String.format(format, args), Toast.LENGTH_SHORT);
        toast.show();
    }

    public static void show(Context context, int resId, int duration, Object... args) {
        if(context==null)return;
        if(toast != null)
            toast.cancel();
        toast = Toast.makeText(context, String.format(context.getResources().getString(resId), args), Toast.LENGTH_SHORT);
        toast.show();
    }

    public static void show(Context context, String format, int duration, Object... args) {
        if(context==null)return;
        if(toast != null)
            toast.cancel();
        toast = Toast.makeText(context, String.format(format, args), Toast.LENGTH_SHORT);
        toast.show();
    }
}
